package cn.zhuwj.autodiscovery.config;

import java.util.concurrent.ThreadPoolExecutor;

/**
 * @author zhuwj.cn
 */
public class StartConfig {

    private String ip;
    private Integer port;

    private String startIp;
    private String endIp;

    private Integer startPort;
    private Integer endPort;

    private Integer threadCount;

    private Callback callback;

    public String getIp() {
        return ip;
    }

    public void setIp(String ip) {
        this.ip = ip;
    }

    public Integer getPort() {
        return port;
    }

    public void setPort(Integer port) {
        this.port = port;
    }

    public String getStartIp() {
        return startIp;
    }

    public void setStartIp(String startIp) {
        this.startIp = startIp;
    }

    public String getEndIp() {
        return endIp;
    }

    public void setEndIp(String endIp) {
        this.endIp = endIp;
    }

    public Integer getStartPort() {
        return startPort;
    }

    public void setStartPort(Integer startPort) {
        this.startPort = startPort;
    }

    public Integer getEndPort() {
        return endPort;
    }

    public void setEndPort(Integer endPort) {
        this.endPort = endPort;
    }

    public Integer getThreadCount() {
        return threadCount;
    }

    public void setThreadCount(Integer threadCount) {
        this.threadCount = threadCount;
    }

    public Callback getCallback() {
        return callback;
    }

    public void setCallback(Callback callback) {
        this.callback = callback;
    }

    public interface Callback{

        /**
         * 开始扫描
         * @param total
         */
        void onStart(int total);

        /**
         * 已找到开放端口回调
         * @param ip
         * @param port
         * @param serviceName
         * @param executor
         * @return
         */
        Next onFound(String ip, Integer port, String serviceName, ThreadPoolExecutor executor);

        /**
         * 扫描结束
         * @param ms
         */
        void onFinished(long ms);

        /**
         * 当前进度
         * @param ip
         * @param port
         * @param total
         * @param index
         * @param progress
         * @param ms
         */
        void onProgress(String ip, Integer port, int total, int index, int progress, long ms);
    }

    /**
     * 接下来的操作
     */
    public enum Next{
        /** 继续扫描 */
        CONTINUE_SCAN,
        /** 停止扫描 */
        STOP_SCAN;
    }

    @Override
    public String toString() {
        return "StartConfig{" +
                "ip='" + ip + '\'' +
                ", port=" + port +
                ", startIp='" + startIp + '\'' +
                ", endIp='" + endIp + '\'' +
                ", startPort=" + startPort +
                ", endPort=" + endPort +
                ", threadCount=" + threadCount +
                ", callback=" + callback +
                '}';
    }
}
